package cn.com.wxd.service.freemarker.template;

import java.io.IOException;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.com.wxd.service.freemarker.core.FreeMarkerNoFile;
import cn.com.wxd.service.freemarker.core.TemplateNoFile;
import cn.com.wxd.common.framedata.FrameDataUtil;

/**
 * Title:SmsTemplate.java
 * Description:cn.com.wxd.service.freemarker
 * <p>
 * Company: 短信模板类
 * Copyright: Copyright (c) 2015
 * All right reserved.
 * Created time: 2016-4-12 下午12:15:05
 *
 * @author WangXuDong
 * @version 1.0
 */
public class SmsTemplate implements TemplateNoFile {
    private static final Logger log = LoggerFactory.getLogger(SmsTemplate.class);
    private static final String TEMPLATE_PREFIXION = "template_sms_";

    @Override
    public String getTemplate(String tempName, HashMap<String, String> data) {
        FreeMarkerNoFile fmnf = new FreeMarkerNoFile();
        String templateStr = null;
        try {
            templateStr = FrameDataUtil.getDataByName(TEMPLATE_PREFIXION + tempName);
        } catch (Exception e) {
            log.error("", e);
        }
        if (templateStr == null) {
            return null;
        }
        templateStr = fmnf.process(templateStr, data);
        return templateStr;
    }

    @Override
    public void generTempFile(String tempName, HashMap<String, String> data,
                              String filePath) {
        FreeMarkerNoFile fmnf = new FreeMarkerNoFile();
        try {
            fmnf.processToFile(tempName, data, filePath);
        } catch (IOException e) {
            log.error("", e);
        }
    }
}
